/* coherent noise function over 1, 2 or 3 dimensions */
/* (copyright Ken Perlin) */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <libge/gefile.h>

#define _B 0x100
#define _BM 0xff

#define _N 0x1000
#define _NP 12   /* 2^N */
#define _NM 0xfff

static int p[_B + _B + 2];
static float g3[_B + _B + 2][3];
static float g2[_B + _B + 2][2];
static float g1[_B + _B + 2];
static int start = 1;

static void init(void);

#define s_curve(t) ( t * t * (3. - 2. * t) )

#define lerp(t, a, b) ( a + t * (b - a) )

#define setup(i,b0,b1,r0,r1)\
	t = vec[i] + _N;\
	b0 = ((int)t) & _BM;\
	b1 = (b0+1) & _BM;\
	r0 = t - (int)t;\
	r1 = r0 - 1.;

double noise1(double arg)
{
	int bx0, bx1;
	float rx0, rx1, sx, t, u, v, vec[1];

	vec[0] = arg;
	if (start) {
		start = 0;
		init();
	}

	setup(0, bx0,bx1, rx0,rx1);

	sx = s_curve(rx0);

	u = rx0 * g1[ p[ bx0 ] ];
	v = rx1 * g1[ p[ bx1 ] ];

	return lerp(sx, u, v);
}

float noise2(float* vec)
{
	int bx0, bx1, by0, by1, b00, b10, b01, b11;
	float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
	register int i, j;

	if (start) {
		start = 0;
		init();
	}

	setup(0, bx0,bx1, rx0,rx1);
	setup(1, by0,by1, ry0,ry1);

	i = p[ bx0 ];
	j = p[ bx1 ];

	b00 = p[ i + by0 ];
	b10 = p[ j + by0 ];
	b01 = p[ i + by1 ];
	b11 = p[ j + by1 ];

	sx = s_curve(rx0);
	sy = s_curve(ry0);

#define at2(rx,ry) ( rx * q[0] + ry * q[1] )

	q = g2[ b00 ] ; u = at2(rx0,ry0);
	q = g2[ b10 ] ; v = at2(rx1,ry0);
	a = lerp(sx, u, v);

	q = g2[ b01 ] ; u = at2(rx0,ry1);
	q = g2[ b11 ] ; v = at2(rx1,ry1);
	b = lerp(sx, u, v);

	return lerp(sy, a, b);
}

float noise3(float vec[3])
{
	int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
	float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
	register int i, j;
	
	if (start) {
		printf("plop s\n");
		start = 0;
		init();
	}

	setup(0, bx0,bx1, rx0,rx1);
	setup(1, by0,by1, ry0,ry1);
	setup(2, bz0,bz1, rz0,rz1);

	i = p[ bx0 ];
	j = p[ bx1 ];

	b00 = p[ i + by0 ];
	b10 = p[ j + by0 ];
	b01 = p[ i + by1 ];
	b11 = p[ j + by1 ];

	t  = s_curve(rx0);
	sy = s_curve(ry0);
	sz = s_curve(rz0);

#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )

	q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0);
	q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0);
	a = lerp(t, u, v);

	q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0);
	q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0);
	b = lerp(t, u, v);

	c = lerp(sy, a, b);

	q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1);
	q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1);
	a = lerp(t, u, v);

	q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1);
	q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1);
	b = lerp(t, u, v);

	d = lerp(sy, a, b);

	return lerp(sz, c, d);
}

static void normalize2(float v[2])
{
	float s;

	s = sqrt(v[0] * v[0] + v[1] * v[1]);
	v[0] = v[0] / s;
	v[1] = v[1] / s;
}

static void normalize3(float v[3])
{
	float s;

	s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
	v[0] = v[0] / s;
	v[1] = v[1] / s;
	v[2] = v[2] / s;
}

static int random_seed = 0;
static int random_seed_table[];
static int n;
int perlin_random(){
	int ret = random_seed_table[n] ^ random_seed;
	n++;
	if(n >= 2048){
		n = 0;
	}
//	return rand();
	return ret;
}

static void init(void)
{
	int i, j, k;
//	srand(time(NULL));
//	srand(geGetTick());
//	srand(j*42+geGetTick()*rand());

	for (i = 0 ; i < _B ; i++) {
		p[i] = i;

		g1[i] = (float)((perlin_random() % (_B + _B)) - _B) / _B;

		for (j = 0 ; j < 2 ; j++)
			g2[i][j] = (float)((perlin_random() % (_B + _B)) - _B) / _B;
		normalize2(g2[i]);

		for (j = 0 ; j < 3 ; j++)
			g3[i][j] = (float)((perlin_random() % (_B + _B)) - _B) / _B;
		normalize3(g3[i]);
	}

	while (--i) {
		k = p[i];
		p[i] = p[j = perlin_random() % _B];
		p[j] = k;
	}

	/*
	int _buf[2048];
	int* buf = _buf;
	char sbuf[65536];
	for(i=0; i<2048; i++){
		buf[i] = random();
	}
	ge_File* bin = geFileOpen("C:/rand.c", GE_FILE_MODE_WRITE | GE_FILE_MODE_BINARY);
	sprintf(sbuf, "static int random_seed_table[2048] = {\n");
	for(i=0; i<2048; i+=16){
		sprintf(sbuf, "%s\t %d, %d, %d, %d, %d, %d, %d, %d,  %d, %d, %d, %d, %d, %d, %d, %d,\n", sbuf, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]);
		buf+= 16;
	}
	sprintf(sbuf, "%s};\n", sbuf);
	geFileWrite(bin, sbuf, strlen(sbuf));
	geFileClose(bin);
	*/

	for (i = 0 ; i < _B + 2 ; i++) {
		p[_B + i] = p[i];
		g1[_B + i] = g1[i];
		for (j = 0 ; j < 2 ; j++)
			g2[_B + i][j] = g2[i][j];
		for (j = 0 ; j < 3 ; j++)
			g3[_B + i][j] = g3[i][j];
	}
}

float perlin_noise_2D(float vec[2], int terms, float freq, int seed){
	float v[2] = { vec[0]*freq, vec[1]*freq };

	float result = 0.0;
	float amp = 1.0;

	random_seed = seed;

	int i;
	for(i=0; i<terms; i++ ){
		result += noise2(v)*amp;
		v[0] *= 2.0;
		v[1] *= 2.0;
		amp *= 0.5;
	}

	return result;
}


static int random_seed_table[2048] = {
	 11854, 21598, 23215, 28141, 21140, 22186, 19637, 23132,  15876, 6500, 12204, 332, 26098, 9889, 26402, 29349,
	 10998, 27559, 15892, 21760, 17043, 3074, 15792, 29024,  25622, 27349, 24927, 10012, 15553, 24175, 19459, 23584,
	 28457, 16926, 25213, 15702, 8669, 23112, 28531, 25438,  24904, 16055, 13392, 12165, 22745, 16181, 2956, 29941,
	 10081, 30297, 45, 16937, 21180, 32416, 32398, 24228,  7859, 32191, 607, 20707, 19233, 31288, 26093, 144,
	 32085, 12076, 13987, 18680, 22712, 21104, 13009, 4031,  2735, 227, 21677, 13266, 19907, 17662, 3736, 26782,
	 10240, 27564, 7330, 20864, 26778, 7004, 3919, 29052,  10455, 24917, 29596, 17201, 21544, 10570, 15421, 3340,
	 31641, 21295, 20521, 17853, 30828, 23371, 25176, 7399,  8705, 18573, 30411, 31772, 6906, 21795, 14542, 5128,
	 31132, 1353, 1658, 18924, 20343, 8287, 21885, 6479,  21577, 16447, 21790, 15856, 14368, 27341, 29051, 14846,
	 24767, 27088, 7189, 3211, 5699, 21760, 32143, 11327,  25350, 607, 29875, 6729, 10948, 20685, 1718, 8603,
	 15612, 215, 9405, 5719, 26265, 4049, 27295, 10628,  18130, 18724, 15085, 9478, 27471, 488, 23600, 9165,
	 30605, 12982, 31601, 6732, 23427, 25527, 14335, 17197,  23942, 7937, 7276, 17475, 31594, 23844, 10457, 8128,
	 26346, 8191, 21107, 17832, 8521, 12249, 7230, 22917,  31290, 11949, 11538, 93, 30206, 30148, 1763, 19169,
	 24268, 29065, 17221, 4071, 1397, 28570, 31022, 19226,  30024, 4891, 12286, 21488, 7987, 25423, 958, 221,
	 16428, 10345, 24229, 2759, 1743, 2719, 27617, 17593,  15433, 10113, 10132, 31707, 29812, 4489, 12316, 5026,
	 2371, 28147, 15511, 12868, 25953, 9422, 23718, 4463,  25109, 22356, 25970, 18234, 15465, 4215, 12269, 7004,
	 25995, 25532, 3163, 15515, 12915, 28236, 3856, 27272,  11974, 28233, 6779, 26474, 5883, 25694, 19043, 18040,
	 15804, 29594, 9329, 27211, 24719, 29566, 12783, 18322,  12213, 26708, 26319, 16392, 3410, 21955, 31215, 10659,
	 18383, 8097, 4763, 22030, 21373, 27912, 28500, 11866,  18299, 16812, 27087, 14065, 8665, 16747, 31809, 4043,
	 5885, 21030, 11226, 17636, 28742, 4048, 31887, 749,  15856, 18116, 21021, 1089, 24632, 26716, 25163, 18972,
	 11200, 11711, 7279, 30215, 11572, 23802, 10803, 22423,  20526, 25683, 28057, 599, 27991, 16345, 8253, 3,
	 976, 23872, 30683, 29431, 8656, 29164, 29712, 15590,  16526, 30540, 14693, 32207, 5985, 16745, 7561, 32557,
	 10789, 25535, 18654, 24431, 5858, 22603, 4407, 4519,  26280, 7397, 29153, 1414, 26045, 15056, 17632, 2952,
	 18171, 27792, 8570, 18796, 5747, 22011, 1018, 21223,  16214, 659, 8878, 15001, 10518, 7699, 5170, 12096,
	 12232, 6984, 10992, 31020, 31693, 15650, 10728, 27635,  31921, 13835, 13997, 8293, 2899, 20855, 11440, 2754,
	 30534, 23485, 13761, 16683, 888, 15397, 19411, 1623,  5649, 30018, 2048, 27783, 8094, 32642, 25293, 9404,
	 32111, 12803, 18862, 20007, 23357, 11688, 11725, 23009,  22545, 32365, 28679, 22236, 29280, 26359, 20023, 14874,
	 32635, 2672, 13752, 30492, 12839, 26769, 7973, 31902,  29831, 24576, 22371, 27009, 6467, 10973, 23010, 3593,
	 10211, 2455, 8223, 3400, 18556, 4101, 2670, 13018,  4751, 18610, 17910, 20691, 17198, 8824, 21501, 14838,
	 7776, 23632, 5734, 11304, 32711, 25448, 1399, 16164,  24192, 22390, 29408, 11119, 18507, 10573, 32249, 32143,
	 6124, 1965, 7500, 2424, 27345, 3680, 24915, 12871,  6644, 27522, 21635, 23090, 14851, 28449, 7305, 3775,
	 26303, 14598, 16595, 17717, 23970, 30929, 14930, 15184,  11204, 29772, 12414, 20537, 29439, 18425, 1947, 27061,
	 2641, 5613, 9275, 14749, 32131, 5857, 2053, 30606,  12296, 16775, 11188, 25313, 10024, 31770, 14947, 8414,
	 16222, 3129, 4615, 19244, 20734, 14581, 11581, 17036,  2074, 21289, 23110, 6600, 29607, 6154, 25423, 11493,
	 4060, 8702, 3062, 14496, 20443, 23474, 2059, 1561,  27283, 10598, 20371, 32457, 28389, 15500, 29715, 15545,
	 25349, 17810, 23307, 27382, 29476, 30716, 448, 2624,  29516, 5301, 11838, 28162, 14475, 28327, 12702, 1415,
	 3411, 7561, 8069, 17770, 17697, 21240, 7917, 17742,  13149, 1482, 14376, 26064, 2433, 26527, 17441, 4794,
	 24702, 22712, 24806, 30073, 29020, 19981, 3939, 11218,  16672, 23961, 24176, 22224, 17394, 25849, 18191, 5633,
	 15231, 32309, 7662, 17122, 21661, 14046, 15924, 151,  18477, 15705, 20858, 29663, 838, 30842, 22806, 14152,
	 6800, 15701, 23712, 24479, 3309, 5968, 25007, 9387,  6495, 22141, 4324, 539, 11302, 22567, 11306, 25788,
	 10024, 15787, 14907, 14319, 2454, 1417, 2919, 26459,  15053, 15035, 31633, 10463, 31866, 11846, 5498, 8906,
	 18434, 28430, 31554, 16975, 6945, 29678, 14379, 22067,  30673, 11272, 24481, 16841, 7021, 26970, 7543, 23584,
	 12566, 22931, 7028, 20347, 854, 292, 24590, 3329,  28931, 27801, 2677, 10422, 10598, 3114, 4051, 12714,
	 29597, 28045, 24018, 23153, 1342, 18447, 1632, 1490,  11325, 3811, 22703, 3011, 20496, 32186, 2943, 19094,
	 3600, 21396, 23711, 22637, 29987, 12245, 18865, 26867,  9368, 17819, 17967, 15182, 21074, 22863, 4779, 9295,
	 31785, 15482, 6491, 2284, 18573, 15322, 29652, 23793,  23148, 13238, 32278, 31218, 7254, 15982, 6857, 25220,
	 18144, 12630, 3270, 17837, 9798, 23492, 2521, 22168,  25428, 15464, 27333, 19597, 21382, 8412, 7305, 7969,
	 5230, 25468, 14050, 21162, 30294, 15224, 23569, 26870,  31271, 21288, 17886, 19005, 26249, 6303, 9181, 14931,
	 14412, 31874, 12016, 11810, 29191, 4891, 5645, 5464,  3838, 19369, 10306, 27741, 7497, 12794, 24566, 10888,
	 17203, 28220, 13169, 24722, 13281, 30481, 20127, 6987,  22324, 10721, 6672, 24203, 10479, 15732, 13124, 19564,
	 4893, 17088, 14886, 19638, 18349, 10239, 6102, 18587,  23904, 29189, 8875, 20133, 13285, 8145, 17273, 13036,
	 25410, 27746, 15, 32652, 14965, 25292, 3844, 18774,  4443, 30858, 22708, 15558, 29138, 8726, 2437, 30517,
	 23578, 5559, 6511, 80, 10882, 12442, 27835, 30665,  22592, 12837, 29194, 19277, 12192, 16776, 24986, 2229,
	 9057, 29077, 453, 8320, 22363, 14033, 5322, 11393,  7270, 971, 21456, 3797, 25464, 32684, 6952, 32024,
	 27661, 2832, 11219, 19416, 12748, 1812, 9796, 3658,  23911, 4784, 8806, 24124, 15555, 12872, 2273, 24651,
	 1625, 5501, 4506, 22614, 27612, 28489, 2936, 25139,  16411, 5195, 20846, 8864, 13354, 21343, 4278, 1148,
	 28604, 15474, 17498, 22071, 2260, 18837, 2553, 23431,  7837, 7759, 13256, 10076, 7061, 20792, 15319, 21015,
	 25329, 29635, 31894, 24566, 27966, 19548, 21143, 27603,  6212, 30387, 2965, 27151, 11823, 24151, 18102, 6089,
	 26609, 18310, 10765, 27219, 28386, 23108, 4451, 4838,  8617, 25514, 6711, 27284, 8288, 16769, 12547, 23167,
	 25587, 11279, 961, 5193, 25801, 21041, 32174, 11979,  5287, 31658, 12366, 31498, 12241, 9659, 19888, 9574,
	 10610, 19956, 6131, 30485, 14141, 24393, 27145, 19408,  16469, 30056, 15803, 4044, 13162, 27210, 21229, 23020,
	 2085, 25096, 23588, 30261, 28615, 18673, 21573, 29826,  30989, 30681, 24992, 3961, 11094, 29363, 27180, 32701,
	 23815, 30051, 15636, 3941, 18735, 17101, 30067, 430,  10343, 27186, 31324, 8940, 20733, 30396, 16414, 5319,
	 8785, 15703, 11974, 10915, 16254, 15555, 20965, 27232,  23869, 17383, 13715, 1348, 9991, 21097, 5299, 23861,
	 32634, 26491, 15481, 27180, 8190, 13048, 18730, 5094,  23464, 23727, 8227, 21469, 2399, 22015, 19229, 13174,
	 22845, 27044, 6319, 31356, 6455, 32208, 9748, 8653,  11521, 15485, 13871, 24147, 15660, 5634, 31180, 22582,
	 24978, 20965, 11561, 25168, 19187, 8689, 11957, 17890,  12256, 27528, 29463, 30341, 216, 15162, 31346, 16995,
	 10162, 5782, 10984, 21158, 22074, 8255, 13405, 4145,  10271, 16963, 24957, 16526, 7181, 21161, 31232, 28456,
	 10262, 26185, 6700, 30395, 27990, 17889, 9116, 16136,  20183, 14692, 11073, 717, 28594, 7573, 2214, 12788,
	 23671, 30677, 27256, 17419, 25551, 31801, 5189, 3828,  25184, 14816, 10628, 30174, 1521, 24964, 10710, 1140,
	 19407, 23118, 651, 19027, 15983, 6383, 22888, 2754,  13908, 27884, 29863, 5277, 8755, 14393, 25664, 22163,
	 6742, 17674, 20583, 914, 17214, 11750, 4438, 23422,  17292, 3069, 29772, 27689, 20770, 24507, 20950, 24192,
	 6533, 26525, 22861, 9218, 2437, 22852, 13728, 6263,  14369, 12488, 28499, 27614, 30885, 2638, 12232, 26791,
	 22549, 14813, 18878, 27170, 2510, 5485, 11031, 5944,  1899, 9537, 7134, 13657, 26598, 11895, 28296, 10165,
	 12799, 19422, 1402, 28335, 11746, 2311, 20940, 15246,  31236, 13215, 12109, 27766, 26446, 22267, 16839, 1176,
	 24701, 5621, 14212, 29861, 24777, 22263, 5392, 18312,  15812, 30293, 28225, 1876, 18566, 29408, 12405, 28283,
	 2567, 18616, 25115, 14658, 7884, 28257, 31605, 11121,  30150, 10265, 15515, 7759, 30327, 9577, 9412, 10957,
	 21078, 7419, 28353, 17410, 1397, 23211, 14026, 21975,  19041, 29664, 11645, 15364, 1353, 5661, 31780, 9531,
	 27235, 9171, 15927, 13986, 25484, 4986, 13346, 903,  31023, 17631, 4935, 11600, 16999, 16576, 5959, 16304,
	 8296, 5782, 14461, 7457, 18715, 19634, 11212, 3982,  25864, 5771, 3995, 20815, 17529, 17751, 27165, 8795,
	 28636, 9944, 23766, 15801, 5994, 18041, 12635, 17208,  9734, 17561, 9049, 26976, 31592, 14375, 3032, 2984,
	 4474, 20079, 20929, 26858, 4354, 7475, 17310, 9747,  6530, 23294, 16034, 26911, 16476, 29109, 18153, 8261,
	 2874, 8047, 29952, 18798, 27053, 6534, 23720, 19948,  29205, 26095, 20695, 18025, 26048, 24262, 10496, 15133,
	 16470, 5165, 27540, 13381, 22132, 87, 457, 11984,  18327, 16864, 22682, 18779, 18236, 20576, 4879, 15711,
	 325, 24383, 12734, 30889, 7583, 25291, 21394, 27403,  10018, 27527, 29643, 23634, 22968, 19398, 18758, 24183,
	 7106, 15225, 11007, 12314, 9911, 28230, 7636, 9003,  8974, 20442, 28556, 23531, 15199, 23167, 791, 31763,
	 27333, 15345, 12823, 3666, 2694, 15469, 26528, 17917,  25334, 7180, 22588, 26371, 17304, 23119, 31539, 27167,
	 26247, 7163, 10505, 12625, 8980, 8999, 839, 24718,  13233, 3475, 2431, 11959, 4878, 19771, 32650, 17096,
	 13441, 3884, 2324, 29010, 7083, 1175, 7771, 28203,  5977, 16932, 15923, 18019, 9128, 10632, 334, 13947,
	 14189, 4442, 29370, 12498, 211, 7970, 20907, 10336,  21830, 1972, 8315, 29606, 22672, 10684, 9455, 23525,
	 8002, 13977, 15804, 11407, 20566, 23919, 12617, 22267,  2578, 11383, 22967, 32348, 3632, 7322, 21023, 32756,
	 31035, 31551, 2330, 19333, 2364, 9825, 23687, 8201,  14230, 20196, 8840, 162, 10799, 13609, 17358, 30164,
	 16336, 5088, 19223, 28402, 15311, 11549, 3572, 22486,  21739, 11694, 21200, 14037, 11127, 23213, 6190, 26355,
	 27323, 15697, 24882, 16978, 6551, 16649, 11107, 20721,  24169, 30668, 29103, 20371, 14897, 30890, 24752, 8956,
	 32499, 3240, 8237, 2915, 1373, 7626, 21988, 11301,  26026, 7281, 17798, 15287, 14278, 20199, 12804, 28638,
	 7859, 16185, 25609, 31266, 9003, 15173, 31175, 10368,  8583, 6931, 25591, 32351, 20191, 16745, 13339, 22981,
	 6515, 2713, 8199, 30923, 26697, 7582, 24223, 29518,  32280, 21351, 16866, 31976, 869, 10355, 12840, 798,
	 31724, 27806, 28327, 31707, 11073, 9531, 14140, 30750,  11447, 21858, 17257, 20207, 17025, 8331, 10906, 29847,
	 8215, 31580, 8620, 21008, 13276, 24256, 12719, 12475,  13309, 12601, 19435, 3665, 29340, 23159, 24354, 27932,
	 15662, 13609, 21013, 29799, 19233, 21267, 1865, 30003,  32706, 18273, 19979, 10027, 863, 27451, 25778, 12762,
	 30632, 20633, 28708, 22044, 19291, 22361, 3228, 19410,  28961, 6287, 23466, 10202, 32179, 7196, 13179, 24127,
	 28992, 3202, 21338, 13484, 12307, 23798, 16759, 14631,  28273, 5559, 13799, 4347, 5056, 15007, 14061, 13302,
	 22767, 32759, 19064, 26581, 9745, 16784, 24812, 4093,  29515, 28687, 23845, 9580, 12529, 26761, 23994, 27374,
	 31468, 27216, 11134, 12692, 7007, 7948, 29005, 16738,  8330, 26893, 8453, 14920, 2542, 27615, 10706, 340,
	 20657, 799, 25519, 3621, 20293, 7054, 21545, 11427,  19525, 8804, 12390, 1773, 11423, 32487, 16487, 2963,
	 4344, 19003, 1930, 1030, 25164, 14716, 22099, 28492,  4565, 28170, 10603, 29944, 4143, 8228, 31209, 1114,
	 16313, 22457, 25297, 29683, 26174, 10106, 16346, 13611,  25045, 7732, 10613, 28743, 9477, 25181, 29194, 7317,
	 15917, 11245, 2181, 26857, 28195, 4207, 25617, 2125,  4636, 21847, 23843, 14069, 25804, 15510, 6075, 2929,
	 23246, 32620, 25319, 26662, 7749, 27517, 12680, 8447,  28100, 22056, 4184, 10592, 25195, 23060, 15660, 24156,
	 24915, 4875, 17271, 16679, 15405, 19468, 16912, 13774,  17701, 21403, 15925, 6693, 23053, 27228, 10191, 18689,
	 10935, 32736, 29431, 23976, 16034, 12735, 27322, 19334,  32217, 16615, 8473, 7714, 16665, 28979, 8276, 30032,
	 11570, 1856, 16745, 4519, 23983, 22652, 19415, 1333,  8889, 8575, 17063, 23666, 22073, 5791, 685, 21363,
	 3133, 25278, 5644, 27488, 8861, 2151, 24824, 29736,  29662, 22810, 3008, 24179, 12630, 30435, 19979, 27097,
	 10385, 5169, 32609, 849, 30708, 26086, 4334, 26604,  30368, 31659, 21635, 24515, 21402, 29318, 13534, 9517,
	 12328, 13742, 17195, 19510, 14718, 16798, 15819, 15949,  1433, 7528, 29779, 7741, 14188, 32332, 11480, 10335,
	 11834, 18825, 28266, 25357, 17475, 26739, 21726, 13145,  24738, 8902, 20945, 10751, 24694, 29498, 32489, 7321,
	 6976, 2647, 25950, 24338, 1676, 29579, 24249, 12637,  15572, 4218, 29404, 13671, 27553, 24213, 22339, 330,
	 27891, 15086, 29577, 8643, 4067, 6218, 3886, 8422,  21639, 23416, 3223, 25872, 7958, 20962, 21846, 31774,
	 9804, 30306, 23468, 9948, 8464, 30807, 21836, 14528,  30549, 14583, 4962, 8153, 31294, 13031, 7124, 10498,
	 26501, 9, 26568, 21595, 15389, 29077, 27494, 19962,  6678, 28267, 19167, 24285, 17858, 2983, 24750, 27171,
	 32278, 4982, 31006, 19068, 13394, 28201, 26380, 9183,  26341, 8584, 21998, 32123, 9098, 23145, 32020, 14319,
	 29880, 13441, 6190, 13245, 15929, 13433, 18703, 15356,  19736, 10308, 18096, 2382, 7873, 25009, 32120, 28946,
	 9060, 32572, 1210, 5339, 32666, 14122, 3456, 9760,  4427, 22741, 11911, 4661, 15311, 30788, 12682, 10873,
	 16211, 30718, 17859, 7378, 8063, 25888, 15280, 20566,  23894, 22958, 11795, 31307, 2141, 22823, 15420, 32594,
	 27391, 23388, 14730, 29919, 22064, 31105, 30256, 22252,  20561, 29061, 1333, 17903, 11091, 29599, 9151, 24841,
	 17952, 28202, 9616, 4224, 32054, 19378, 2769, 21615,  3733, 22351, 8974, 27580, 29916, 15153, 24963, 26443,
	 32175, 19837, 18070, 32113, 8027, 8024, 676, 12716,  20925, 576, 13824, 9361, 28256, 30627, 29241, 8197,
	 23525, 16042, 24732, 13232, 2216, 29782, 12794, 30127,  30880, 31183, 15276, 15241, 27271, 5369, 26067, 24421,
	 22587, 32583, 20196, 25978, 22117, 22228, 18533, 5574,  5976, 9648, 4337, 24067, 5436, 29559, 28546, 4055,
};
